package com.lzj.test3;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lzj.test3.Date.CalendarView;
import com.lzj.test3.Date.WeekView;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class Main2Activity extends AppCompatActivity {

    private WeekView mWeek;
    private CalendarView mCalender;

    private ImageView mImg_left,mImg_right;
    private TextView mTv_data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        mCalender=findViewById(R.id.mCalender);
        mWeek=findViewById(R.id.mWeek);
        mTv_data=findViewById(R.id.mTv_data);
        mImg_right=findViewById(R.id.mImg_right);
        mImg_left=findViewById(R.id.mImg_left);
        // 设置已选的日期
        mCalender.setSelectDate(initData());

        mImg_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                last(v);
            }
        });

        mImg_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                next(v);
            }
        });

        mCalender.setOnDataClickListener(new CalendarView.OnDataClickListener() {
            @Override
            public void onDataClick(@NonNull CalendarView view, int year, int month, int day) {
                Toast.makeText(Main2Activity.this,"year: " + year+"month,: " + (month + 1)+"day: " + day,Toast.LENGTH_LONG).show();
                Log.e("test", "year: " + year);
                Log.e("test", "month,: " + (month + 1));
                Log.e("test", "day: " + day);
            }
        });


        setCurDate();
    }

    private List<String> initData() {
        List<String> dates = new ArrayList<>();
//        Calendar calendar = Calendar.getInstance(Locale.CHINA);
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", Locale.CHINA);
//        sdf.format(calendar.getTime());
//        dates.add(sdf.format(calendar.getTime()));
        dates.add("20200505");
        dates.add("20200518");
        dates.add("20200521");
        dates.add("20200621");
        dates.add("20200622");
        dates.add("20200623");
        dates.add("20200624");
        return dates;
    }

    public void next(View v){
        mCalender.nextMonth();
        setCurDate();
    }

    public void last(View v){
        mCalender.lastMonth();
        setCurDate();
    }

    private void setCurDate(){
        String month= String.valueOf((mCalender.getMonth() + 1));
        if (month.length()<2){
            month="0"+month;
        }
        mTv_data.setText(mCalender.getYear() + "/" + month);
    }
}
